package by.artureg.so.conf;

import org.apache.commons.lang.StringUtils;
import org.simpleframework.xml.Attribute;
import org.simpleframework.xml.Root;
import org.simpleframework.xml.core.Commit;

@Root(name = "Parameter")
public class Parameter {
    @Attribute
    private String name;
    @Attribute(required = false)
    private String label;
    @Attribute(required = false)
    private String type;
    @Attribute(required = false)
    private String format;
    @Attribute(name = "default", required = false)
    private String defaultValue;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getLabel() {
        return label;
    }

    public void setLabel(String label) {
        this.label = label;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getFormat() {
        return format;
    }

    public void setFormat(String format) {
        this.format = format;
    }

    @Commit
    public void commit() {
        if (StringUtils.isNotEmpty(defaultValue) && (Const.DATETIME.equals(type) || Const.DATE.equals(type))) {
            defaultValue = Const.defDate(defaultValue).getTime() + "";
        }
    }

    public String getDefaultValue() {
        return defaultValue;
    }

    public void setDefaultValue(String defaultValue) {
        this.defaultValue = defaultValue;
    }
}
